package com.mslinn.yumifier.model {
    import com.mslinn.yumifier.Services;
    
    import mx.collections.ArrayCollection;


    [Bindable] public class AppModel {
        private static var instance:AppModel = new AppModel();
        
        public var linkCount:int = 0;

        /** Make sure this is always valid */
        public var serviceUrlJson:String = "http://feeds.delicious.com/v2/json/tags/";
        
        /** Make sure this is always valid */
        public var serviceUrl:String = "https://api.del.icio.us";
        
        public var userId:String = "";
        public var password:String = "";

        /** Array of Item */
        public var items:ArrayCollection = new ArrayCollection();
        
        /** Array of Tag */
        public var tags:ArrayCollection = new ArrayCollection();
        
        public var selectorValue:String = "all";

        /** Filters returned tags; null means disable this filter */
        public var selectedTag:String;

        /** Filters returned tags; null means disable this filter */
        public var selectedDate:Date;
        
        
        public function AppModel() {
        }
        
        public static function getInstance():AppModel { return instance; }
        
        public function reset():void {
            linkCount = 0;
            items.removeAll();
            tags.removeAll();
            selectedTag = "";
            selectedDate = null;
        }
        
        /** @return -1 if tag name is not found */
        public function tagIndexOfName(name:String):int {
            var i:int = 0;
            for each (var tag:Tag in tags) {
                if (tag.name==name)
                    return i;
                i++;
            }
            return -1;
        }
    }
}